import { Compiler, Component, ComponentFactory, Input, NgModule } from "@angular/core";
import { AppSharedModule } from "@app/shared/app-shared.module";
import { WorkFlowCommonShareModule } from "@app/shared/common/workflow/wrokflow-common-component/wrokflow-common-share.module";
import { MainSharedModule } from "../shared/main-shared.module";


export async function createWfFormComponentFactory(compiler: Compiler, templateStr: string, constructor: any): Promise<ComponentFactory<any>> {

    const tmpCmp = Component({ template: templateStr })(
        new constructor().constructor
    );

    const tmpModule = NgModule({
        imports: [AppSharedModule, MainSharedModule, WorkFlowCommonShareModule],
        declarations: [tmpCmp],
        // providers: [] - e.g. if your dynamic component needs any service, provide it here.
    })(class { });

    let moduleWithComponentFactory = await compiler.compileModuleAndAllComponentsAsync(tmpModule);
    return moduleWithComponentFactory.componentFactories.find(x => x.componentType === tmpCmp);
  }
